'use strict';
const { getDataByText } = require('../utils/utils');

class Etf {
  constructor(requestReptile) {
    this.requestReptile = requestReptile;
  }

  async eftList() {
    const url = `http://62.push2.eastmoney.com/api/qt/clist/get?cb=callback&pn=1&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&fid=f3&fs=b:MK0021,b:MK0022,b:MK0023,b:MK0024&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1599051316473`;
    const res = await this.requestReptile(url, 'text');
    const data = getDataByText(res,
      { data: 'data', },
      'data.data.diff',
      'callback'
    );

    const xqUrl = `https://xueqiu.com/service/v5/stock/screener/fund/list?type=18&parent_type=1&order=desc&order_by=percent&page=1&size=30&_=1599051228315`;
    let list = await this.requestReptile(xqUrl, 'json');
    list = list.data.list;
    console.log(list);
    return {
      data,
      list
    };
  }
}

module.exports = Etf;
